package com.ctbu.yyx.cameracontrol.webapi;

import com.ctbu.yyx.cameracontrol.domain.User;
import com.ctbu.yyx.cameracontrol.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/webapi")
public class UserRestController {
    @Autowired
    private UserService userService;

    @GetMapping("/get/{id}")
    public User get(@PathVariable Integer id){
        User user = userService.findById(id);
        return user;
    }

    /**
     * 更新学生方法:/webapi/user/update
     * @param user
     * @return
     */
    @PutMapping("/user/update")
    public User update(User user){
        User olduser=userService.findById(user.getId());
        //if(org.springframework.util.StringUtils.isEmpty(student.getPassword()))
        if(user.getUserPassword().equals("*******")){
            user.setUserPassword(olduser.getUserPassword());
        }
        User user1=userService.update(user);
        return user1;
    }

    /**
     * 删除用户方法:/webapi/user/delete/id
     * @param id
     * @return
     */
    @DeleteMapping("/user/delete/{id}")
    public void delete(@PathVariable Integer id){

        userService.delete(id);
    }

}
